PostgreSQL pg_wait_sampling TPCC性能测试
1 背景知识
本文主要使用 BenchMarksql 6.0 对 PostgreSQL 数据库进行 TPC-C 基准测试,并使用 pg_wait_sampling 扩展记录统计与信息。
2 BenchMarksql 安装与配置
BenchMarksql 是使用 JAVA 语言实现的,底层使用 JDBC 驱动对数据库进行压力测试。此工具使用模拟客户端模拟:查询、多线程组、多用户和应用线程等操作。
本文主要使用 BenchMarksql 6.0 对 PostgreSQL 数据库进行性能测试,并通过 pg_wait_sampling_profile 视图 查看相统计信息。
要完成本章实验,请先完成下面两个步骤。
3 清空统计信息
psql -U postgres -d testdb
#postgres>
SELECT pg_wait_sampling_reset_profile();
Note
这里不传入参数时,默认传入参数 0
,表示清空统计信息。
4 基准测试
- 使用命令行进行基准测试。
su - postgres
cd /soft/benchmarksql/target/run
./runBenchmark.sh my.properties
也可以使用 WEB 运行基准测试,选择其一即可。
5 查看性能视图
完成 Benchmarksql 基准测试 之后。请查询查询 pg_stat_statements 视图 ,确定存在的性能瓶颈和性能优化策略方案。
#postgres>
psql -U postgres -d testdb
5.1 查看等待事件
下面语句将会查询发生次数最多的等待事件的前10名。
--testdb#
SELECT * FROM pg_wait_sampling_profile
ORDER BY count DESC
LIMIT 10;
pid | event_type | event | queryid | count
-------+------------+---------------------+---------+--------
56339 | Activity | LogicalLauncherMain | 0 | 106168
56337 | Activity | AutoVacuumMain | 0 | 106168
56336 | Activity | WalWriterMain | 0 | 106140
56333 | Activity | CheckpointerMain | 0 | 79481
56334 | Activity | BgWriterHibernate | 0 | 72747
56577 | Client | ClientRead | 0 | 62970
56334 | Activity | BgWriterMain | 0 | 33238
56735 | Client | ClientRead | 0 | 30504
56743 | Client | ClientRead | 0 | 30059
56751 | Client | ClientRead | 0 | 29594
(10 rows)
--testdb#
SELECT event,event_type,count(ts) FROM pg_wait_sampling_history
GROUP BY event, event_type;
event | event_type | count
----------------------+------------+-------
CheckpointWriteDelay | Timeout | 834
BgWriterMain | Activity | 20
BgWriterHibernate | Activity | 814
AutoVacuumMain | Activity | 833
ClientRead | Client | 832
LogicalLauncherMain | Activity | 833
WalWriterMain | Activity | 834
(7 rows)
5.2 输出说明
从 pg_wait_sampling_profile 视图 中查询 等待此数
最多的前 10
的等待事件。
从等待事件可以得知 Autovacuum 和 WAL 日志 等待次数最多,可以从这两方面入手进行调优。
6 参考连接
更多信息请参考 PostgreSQL BenchMarksql 6.0 性能测试章节。